//
//  RYDDRenyangzhongCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/14.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit

class RYDDRenyangzhongCell: SYBaseCell, UITableViewDelegate, UITableViewDataSource {
    
    var model: RYDingdanModel!
    
    var tableView: UITableView!
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5
        v.layer.masksToBounds = true
        return v
    }()
    
    var shuView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()

    
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "认养信息"
        return v
    }()
    
    let wuping: RYDingdanWupingView = {
        let v: RYDingdanWupingView = RYDingdanWupingView()
        return v
    }()
    
    let chakan: UIButton = {
        let v: UIButton  = UIButton()
        v.setTitle("查看认养", for: .normal)
        v.setTitleColor(UIColor(hex: 0x367FF6), for: .normal)
        v.titleLabel?.font = 14.autoFontSize()
        v.layer.cornerRadius = 14.autoWidth()
        v.backgroundColor = UIColor(hex: 0xE6EEFE)
        return v
    }()

    
    public var secLineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0xE6E6E6)
        return v
    }()
    
    func configure(_ model: RYDingdanModel) {
        self.model  = model
        wuping.configure(model)
        tableView.reloadData()
    }

    override func initViews() {
        
        chakan.addAction {
            let vc = RYVideoViewController(id: self.model.farmProductId ?? 0)
            self.currentVC.navigationController?.pushViewController(vc, animated: true)
        }
        setTableView()
        self.backgroundColor = .clear
        addSubview(bgView)
        bgView.addSubview(shuView)
        bgView.addSubview(nameLb)
        bgView.addSubview(lineView)
        bgView.addSubview(secLineView)
        bgView.addSubview(wuping)
        bgView.addSubview(tableView)
        bgView.addSubview(chakan)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10.autoWidth())
            make.left.equalToSuperview()
            make.right.equalToSuperview()
        }
        shuView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(shuView)
            make.left.equalTo(shuView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        wuping.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(40.autoWidth())
            make.left.equalToSuperview()
            make.height.equalTo(100.autoWidth())
            make.right.equalToSuperview()
        }
        lineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(155.autoWidth())
            make.left.equalToSuperview().offset(13.autoWidth())
            make.height.equalTo(0.5.autoWidth())
            make.right.equalToSuperview().offset(-13.autoWidth())
        }
        secLineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(273.autoWidth())
            make.left.equalToSuperview().offset(13.autoWidth())
            make.height.equalTo(0.5.autoWidth())
            make.right.equalToSuperview().offset(-13.autoWidth())
        }
        chakan.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-10.autoWidth())
            make.width.equalTo(85.autoWidth())
            make.height.equalTo(28.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
        }
        tableView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(161.autoWidth())
            make.bottom.equalToSuperview().offset(-60.autoWidth())
            make.left.equalToSuperview()
            make.height.equalTo(100.autoWidth())
            make.right.equalToSuperview()
        }
    }
    
    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect(x: 0, y: NAV_HEIGHT, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-NAV_HEIGHT-BOTTOM_SAFE_HEIGHT), style:.plain)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.isScrollEnabled = false
        self.tableView!.register(RYDingdanDetailSubCell.self, forCellReuseIdentifier: "Cell")
        self.contentView.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: RYDingdanDetailSubCell? = tableView.dequeueReusableCell(withIdentifier: "Cell") as? RYDingdanDetailSubCell
        cell?.selectionStyle = .none
        if nil != self.model {
            
            switch indexPath.row {
            case 0:
                cell?.nameLb.text = "认养编号"
                cell?.contentLb.text = model.adoptNumber
            case 1:
                cell?.nameLb.text = "认养状态"
                cell?.contentLb.text = model.getRenyangStatus()
            case 2:
                cell?.nameLb.text = "认养时间"
                cell?.contentLb.text = model.adoptTime
            case 3:
                cell?.nameLb.text = "预计成熟时间"
                cell?.contentLb.text = model.predictMatureTime
                
            default:
                break
            }
        }
        return cell!
    }
}
